/*
 * create_macthreads.c
 * Created on April 11, 2008; 3:29 PM
 * by VRamadurai
 */
#include <pthread.h>
#include <sched.h>
#include "HsTypes.h"

#include "mac_main.h"

#define MAC_STACK_SIZE (4*1024)

/** Stack for MAC **/
hs_uint8_t MacStackBuffer[MAC_STACK_SIZE];

void create_mac_threads()
{
    hs_int32_t siThreadSuccessFlag;
    static pthread_attr_t ThreadAttr;
    static struct sched_param sSched;
    static pthread_t thread_t;

    /* Initialising thread attributes */
    pthread_attr_init(&ThreadAttr);
    sSched.sched_priority = 0;
    pthread_attr_setschedpolicy(&ThreadAttr, SCHED_PIN);

    /** Create MAC thread on Core 1: thread 3 **/
    pthread_attr_setcore_sb(&ThreadAttr, 0);
    sSched.sched_cpuset = 1<<3;
    pthread_attr_setschedparam(&ThreadAttr,&sSched);

    pthread_attr_setstackaddr(&ThreadAttr, MacStackBuffer);
    pthread_attr_setstacksize(&ThreadAttr, MAC_STACK_SIZE);

    siThreadSuccessFlag = pthread_create(&thread_t,&ThreadAttr,mac_main,NULL);
    if(siThreadSuccessFlag != 0)
    {
        printf(" UnsuccessFull Thread Creation %d \n", siThreadSuccessFlag);
    }
}
